﻿using System.Reflection;
using ConsoleApp2.Service;
using ConsoleApp2.Models;

namespace ConsoleApp2.Impl;

public class UserLoginServiceImpl:UserLoginService
{
    private LocalUserSystemService LocalUserSystemService { get; set; }
    private List<ConsoleApp2.Models.User> users { get; set; }
    public UserLoginServiceImpl()
    {
        LocalUserSystemService = new LocalUserSystemServiceImpl();
        users = LocalUserSystemService.GetAllUsers();
    }
    public string BeforeLogin(string UserChose)
    {
        while (true)
        {
            if (UserChose == "1")
            {
                return "1";
            }
            else if (UserChose == "2")
            {
                return "2";
            }
            else if (UserChose == "3")
            {
                return "3";
            }
            else
            {
                Console.WriteLine("输入有误，请重新输入");
                UserChose = Console.ReadLine();
            }
        }
    }

    public ConsoleApp2.Models.User UserNameLogin(ConsoleApp2.Models.User user)
    {
        if (user == null)
        {
            return user;
        }
        users = LocalUserSystemService.GetAllUsers();
        foreach (var item in users)
        {
            if (item.UserName == user.UserName && item.Password == user.Password)
            {
                return item;
            }
        }
        return null;
    }
    
    public  ConsoleApp2.Models.User EmailLogin(ConsoleApp2.Models.User user)
    {
        if (user == null)
        {
            return null;
        }
        foreach (var item in users)
        {
            if (item.Email==user.Email&&item.Password==user.Password)
            {
                return item;;
            }
        }
        return null;
    }
    public ConsoleApp2.Models.User PhoneLogin(ConsoleApp2.Models.User user)
    {
        if (user == null)
        {
            return null;
        }
        foreach (var item in users)
        {
            if (item.Phone==user.Phone&&item.Password==user.Password)
            {
                return item;
            }
        }
        return null;
        
    }
}